<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Strict//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
		<meta http-equiv="pragma" content="no-cache">
		<meta http-equiv="cache-control" content="no-cache">
		<meta http-equiv="expires" content="0"><meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />  
        <title>Welcome to Design Zone......</title>
        <link rel="stylesheet" type="text/css" href="../../scripts/ext/resources/css/ext-all.css" />
        <link rel="stylesheet" type="text/css" href="../../styles/dzbase.css" />
        <script type="text/javascript" src="../../scripts/ext/adapter/ext-base.js">
        </script>
        <script type="text/javascript" src="../../scripts/ext/ext-all.js">
        </script>
		
		<script type="text/javascript" src="../../scripts/menu/EditableItem.js"></script>
		<script type="text/javascript" src="../../scripts/menu/RangeMenu.js"></script>
		<script type="text/javascript" src="../../scripts/grid/GridFilters.js"></script>
		<script type="text/javascript" src="../../scripts/grid/filter/Filter.js"></script>
		<script type="text/javascript" src="../../scripts/grid/filter/StringFilter.js"></script>
		<script type="text/javascript" src="../../scripts/grid/filter/DateFilter.js"></script>
		<script type="text/javascript" src="../../scripts/grid/filter/ListFilter.js">
        </script>
		<script type="text/javascript" src="../../scripts/grid/RowExpander.js">
        </script>
        <script type="text/javascript" src="../../scripts/i18nMessage.js">
        </script>
        <script type="text/javascript" src="../../scripts/utils.js">
        </script>
		
        <script type="text/javascript">
	        var quMessage = new i18nMessage('../../servlet/I18nMessageServlet?keyPrefix=ui.quotation');
	    	var piMessage = new i18nMessage('../../servlet/I18nMessageServlet?keyPrefix=ui.productidentification');
	    	var yarnMessage = new i18nMessage('../../servlet/I18nMessageServlet?keyPrefix=ui.yarn');
	    	var fMessage = new i18nMessage('../../servlet/I18nMessageServlet?keyPrefix=ui.factory');
	    	var ctYarnMaterial = new i18nMessage('../../servlet/CodeTableServlet?name=CtYarnMaterial');
	    	var ctSeasonNumber = new i18nMessage('../../servlet/CodeTableServlet?name=CtSeasonNumber');
	    	var ctCurrency = new i18nMessage('../../servlet/CodeTableServlet?name=CtCurrency');
	        var message = new i18nMessage('../../servlet/I18nMessageServlet?keyPrefix=message');
        	var store;
            var grid;
            
            var deleteCallback = function(btn){
                if (btn == 'yes') {
                    Ext.Ajax.request({
                        url: '../../servlet/QuYarnServlet?action=2&id=' + deleteId,
                        success: function(o){
                            if (o.responseText == 'success') {
                                store.reload();
                                messageTip.msg(message.get('message.tip'), message.get('message.delete.successful'));
                            }
                            else {
                                messageTip.msg(message.get('message.tip'), message.get('message.delete.unsuccessful'));
                            }
                        },
                        failure: function(o){
                            messageTip.msg(message.get('message.tip'), message.get('message.delete.failure'));
                        },
                        params: {
                            foo: 'bar'
                        }
                    });
                }
            }
			
			 Ext.onReady(function(){
                
                store = new Ext.data.Store({
                    url: '../../servlet/QuYarnServlet?action=4',
                    
                    reader: new Ext.data.XmlReader({
                        record: 'item',
                        id: 'id',
                        totalRecords: 'itemTotal'
                    }, [ 
                    'index', 'date','ctSeasonNumber','ctCurrency','price','id',
                    {
						name: 'biYarn.reference', mapping: 'yarnReference'
					},{
						name: 'biYarn.ctYarnMaterial1', mapping: 'ctYarnMaterial'
					},'yarnAccount',{
						name: 'biFactory.name', mapping: 'factoryName'
					},
                    'min1','max1','increase1','price1',
                    'min2','max2','increase2','price2',
                    'min3','max3','increase3','price3',
                    'min4','max4','increase4','price4',
                    'min5','max5','increase5','price5',
                    'comment']),
                    
                    remoteSort: true
                });
                
                store.setDefaultSort('id', 'desc');
				
				var filters = new Ext.grid.GridFilters({
					  filters:[
					    {type: 'string',  dataIndex: 'biYarn.reference'},
					    {type: 'date',  dataIndex: 'date'},
					    {type: 'string',  dataIndex: 'biFactory.name'},{
						      type: 'list',  
						      dataIndex: 'biYarn.ctYarnMaterial1', 
						      options: ctYarnMaterial.getCtArray()
					    },{
						      type: 'list',  
						      dataIndex: 'ctSeasonNumber', 
						      options: ctSeasonNumber.getCtArray()
					    },{
						      type: 'list',  
						      dataIndex: 'ctCurrency', 
						      options: ctCurrency.getCtArray()
					    }
					]});

				var expander = new Ext.grid.RowExpander({
			        tpl : new Ext.XTemplate(
					    '<br/><p><table cellspacing="0" id="the-table" style="width: 60%;margin-left: 60px;">',
					    '<tr><td style="background:#eeeeee; width: 15%;">&nbsp;</td><td style="background:#eeeeee; width: 15%;">' + quMessage.get('ui.quotation.min') + '</td><td style="background:#eeeeee; width: 15%;">'+ quMessage.get('ui.quotation.max') + '</td><td style="background:#eeeeee; width: 15%;">'+ quMessage.get('ui.quotation.increase') + '&nbsp;&nbsp;<b>(%)</b></td><td style="background:#eeeeee; width: 15%;">'+ quMessage.get('ui.quotation.yarnprice') + '&nbsp;/&nbsp;<b>Kg</b></td></tr>',
					    '<tr><td style="background:#eeeeee; width: 15%;">' + quMessage.get('ui.quotation.lot') + '&nbsp;1</td><td style="text-align: center;">{min1}</td><td>{max1}</td><td>{increase1}</td><td>{price1}</td></tr>',
					    '<tr><td style="background:#eeeeee; width: 15%;">' + quMessage.get('ui.quotation.lot') + '&nbsp;2</td><td style="text-align: center;">{min2}</td><td>{max2}</td><td>{increase2}</td><td>{price2}</td></tr>',
					    '<tr><td style="background:#eeeeee; width: 15%;">' + quMessage.get('ui.quotation.lot') + '&nbsp;3</td><td style="text-align: center;">{min3}</td><td>{max3}</td><td>{increase3}</td><td>{price3}</td></tr>',
					    '<tr><td style="background:#eeeeee; width: 15%;">' + quMessage.get('ui.quotation.lot') + '&nbsp;4</td><td style="text-align: center;">{min4}</td><td>{max4}</td><td>{increase4}</td><td>{price4}</td></tr>',
					    '<tr><td style="background:#eeeeee; width: 15%;">' + quMessage.get('ui.quotation.lot') + '&nbsp;5</td><td style="text-align: center;">{min5}</td><td>{max5}</td><td>{increase5}</td><td>{price5}</td></tr>',

					    '</table></p>',
						'<br/><p style="margin-left: 60px;"><b>' + message.get('message.edit.comment') + ':</b> {comment}</p>'
			        )
			    });
                // create the grid
                grid = new Ext.grid.GridPanel({
                    title: quMessage.get('ui.quotation.listdelivery'),
                    store: store,
					stripeRows: true,
					plugins: [filters,expander],
                    height: 560,
                    columns: [expander,{
                        header: message.get('message.list.id'),
                        width: 20,
                        dataIndex: 'index',
                        sortable: false
                    }, {
                        header: message.get('message.edit.reference'),
                        dataIndex: 'biYarn.reference',
                        sortable: true
                    }, {
                        header: yarnMessage.get('ui.yarn.composition'),
                        dataIndex: 'biYarn.ctYarnMaterial1',
                        sortable: true
                    }, {
                        header: yarnMessage.get('ui.yarn.yarnaccount'),
                        dataIndex: 'yarnAccount',
                        sortable: true
                    }, {
                        header: fMessage.get('ui.factory.name'),
                        dataIndex: 'biFactory.name',
                        sortable: true
                    }, {
                        header: quMessage.get('ui.quotation.yarnprice') + '&nbsp;/&nbsp;<b>Kg</b>',
                        width: 80,
                        align: 'right',
                        dataIndex: 'price',
                        sortable: true
                    }, {
                        header: quMessage.get('ui.quotation.currency'),
                        width: 50,
                        dataIndex: 'ctCurrency',
                        sortable: true
                    }, {
                        header: message.get('message.edit.date') + '(d/m/Y)',
                        dataIndex: 'date',
                        sortable: true
                    }, {
                        header: piMessage.get('ui.productidentification.seasonnumber'),
                        dataIndex: 'ctSeasonNumber',
                        sortable: true
                    },{
                        header: message.get('message.list.eidt'),
                        width: 20,
                        dataIndex: 'id',
                        sortable: false,
                        renderer: renderEdit
                    },{
                        header: message.get('message.list.delete'),
                        width: 20,
                        dataIndex: 'id',
                        sortable: false,
                        renderer: renderDelete
                    }],
                    viewConfig: {
                        forceFit: true
                    },
                    loadMask: true,
                    renderTo: 'quIncotermList',
                    bbar: new Ext.PagingToolbar({
                        pageSize: 20,
                        store: store,
                        displayInfo: true
                    })
                });
                
                var startPage = getPrarmeterValue(window.location, 'startPage');
                var start;
                if (startPage == null || startPage == '') {
                    start = 0;
                }
                else {
                    start = (startPage - 1) * 20;
                }
                store.load({
                    params: {
                        start: start,
                        limit: 20
                    }
                });
                
                function renderEdit(value, p, record){
                    return String.format('<a href="delivery_edit.html?id={0}&startPage={1}" target="_self"><img src="../../images/icons/pencil.png" title="' + message.get('message.list.eidt') + '" /></a>', record.id, Math.floor((record.data.index - 1) / 20) + 1);
                }
                
                function renderDelete(value, p, record){
                    return String.format('<a href="javascript: deleteItem(deleteCallback, {0});"><img src="../../images/icons/delete.png" title="' + message.get('message.list.delete') + '"/></a>', record.id);
                }
                
               
                
                
            });
                    
        </script>
    </head>
    <body>
        <div id="quIncotermList">
        </div>
    </body>
</html>
